@inherits RazorFunction
@using System.Text.RegularExpressions
@functions {
    public override string FunctionDescription
    {
        get { return "Plays a Vimeo video."; }
    }

    [FunctionParameter(Label = "Vimeo URL", Help = "The URL to the video on Vimeo, like http://vimeo.com/15195655")]
    public string VimeoURL { get; set; }

    private const string aspectRatioWidgetMarkup = @" <f:widgetfunction xmlns:f='http://www.composite.net/ns/function/1.0' name='Composite.Widgets.String.Selector'>
  <f:param name='Options'>
   <f:function name='Composite.Utils.String.Split'>
    <f:param name='String' value='16:9,4:3' />
   </f:function>
  </f:param>
 </f:widgetfunction>";
    [FunctionParameter(Label = "Aspect Ratio", Help = "16:9 aspect ratio by default", WidgetMarkup = aspectRatioWidgetMarkup, DefaultValue = "16:9")]
    public string AspectRatio { get; set; }

}
@{
    string pattern = @"vimeo\.com/(?:.*#|.*/videos/)?([0-9]+)";
    if (!Regex.IsMatch(VimeoURL, pattern))
    {
        <div class="alert alert-danger">Wrong Vimeo URL.</div>
        return;
    }
    var match = Regex.Match(VimeoURL, pattern);
}

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
    <div class="embed-responsive embed-responsive-@AspectRatio.Replace(":", "by")">
        <iframe class="embed-responsive-item" src="//player.vimeo.com/video/@(match.Groups[1].Value)?byline=0&amp;portrait=0"></iframe>
    </div>
</body>
</html>

